package com.example.newheze.Adapter;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.newheze.Control.RemoteControl;
import com.example.newheze.R;

import java.util.List;

public class RemoteRecycleAdapter extends RecyclerView.Adapter<RemoteRecycleAdapter.itemRemoteRecycleViewHolder> {

    private List<RemoteControl> list;
    private Context context;

    public RemoteRecycleAdapter(Context context,List<RemoteControl> list) {
        this.context = context;
        this.list=list;
    }

    @Override
    public itemRemoteRecycleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.remote_control,parent,false);
        return new itemRemoteRecycleViewHolder(view);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onBindViewHolder(itemRemoteRecycleViewHolder holder, int position) {
        holder.imageView.setImageDrawable(context.getDrawable(list.get(position).getImage_id()));
        holder.textView.setText(list.get(position).getStrDiscription());
        holder.linearLayout.setOnClickListener(list.get(position).getOnClickListener());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class itemRemoteRecycleViewHolder extends RecyclerView.ViewHolder{
        LinearLayout linearLayout;
        ImageView imageView;
        TextView textView;
        public itemRemoteRecycleViewHolder(View itemView) {
            super(itemView);
            linearLayout = itemView.findViewById(R.id.layout_card);
            imageView =itemView.findViewById(R.id.image1);
            textView=itemView.findViewById(R.id.text1);
        }
    }
}
